//
//  My_editAgeVC.m
//  daojiVideo
//
//  Created by tikeios_002 on 2024/5/21.
//

#import "My_editAgeVC.h"
#import "LJYDatePicker.h"

@interface My_editAgeVC ()<LJYDatePickerDelegate>
@property (weak, nonatomic) IBOutlet UIView *footView;
@property (weak, nonatomic) IBOutlet UILabel *nav_title;
@property (weak, nonatomic) IBOutlet UIButton *nav_close;
@property (weak, nonatomic) IBOutlet UIButton *nav_save;
@property (weak, nonatomic) IBOutlet UIView *pickerBg;
@property (weak, nonatomic) IBOutlet UISwitch *openSwitch;
@property (weak, nonatomic) IBOutlet UILabel *tipLabel;
@property (strong, nonatomic)LJYDatePicker *agePicker;
@property (strong, nonatomic)NSString * nowdateStr;
@end

@implementation My_editAgeVC

-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
    
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    self.footView.backgroundColor = viewback_black;
    self.footView.layer.cornerRadius = 18;
    self.footView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
    
    self.openSwitch.transform = CGAffineTransformMakeScale(.81, .81);
 
    [self.nav_close setTitle:NSLocalizedString(@"取消", nil) forState:UIControlStateNormal];
    [self.nav_save setTitle:NSLocalizedString(@"保存", nil) forState:UIControlStateNormal];
    self.nav_title.text = NSLocalizedString(@"年龄", nil);
    self.tipLabel.text = NSLocalizedString(@"展示年龄标签", nil);
    
    NSString *birthdayStr=@"1980-01-01";
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *nowDate=[formatter dateFromString:birthdayStr];
    self.agePicker = [[LJYDatePicker alloc] initWithDatePicker:CGRectMake(0, 0, KScreen_W, 216) MinDate:nowDate MaxDate:[NSDate date]];
    self.agePicker.delegate = self;
    if ([QZUserInfoModel share].birthday != nil && [QZUserInfoModel share].birthday.length > 0) {
        [self.agePicker selectsomeDate:[Tools dateWithString:[QZUserInfoModel share].birthday format:@"yyyy-MM-dd"]];
    }else{
        [self.agePicker selectsomeDate:[NSDate date]];
    }
    [self.pickerBg addSubview:self.agePicker];
    
    if ([[QZUserInfoModel share].is_show_age intValue] == 0) {
        self.openSwitch.on = NO;
    }
}
- (void)textChange:(UITextField *)text{
    if (text.markedTextRange != nil) {
        return; //预输入拼音
    }
}
-(void)selectsomedate:(NSDate*)currentdate andstring:(NSString*)datestring{
    self.nowdateStr = datestring;
    self.nowdateStr = [self.nowdateStr stringByReplacingOccurrencesOfString:@"年" withString:@""];
    self.nowdateStr = [self.nowdateStr stringByReplacingOccurrencesOfString:@"月" withString:@""];
    self.nowdateStr = [self.nowdateStr stringByReplacingOccurrencesOfString:@"日" withString:@""];
}

- (IBAction)closeClick:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)saveClick:(id)sender {
    KMutableDic(sendDic)
    [sendDic setObject:self.nowdateStr forKey:@"value"];
    if (self.openSwitch.on) {
        [sendDic setObject:@(1) forKey:@"is_show_home"];
    }else{
        [sendDic setObject:@(0) forKey:@"is_show_home"];
    }
    KWeakSelf
    [YBNetBase editBirthdayRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            [[QZUserInfoModel share] setValuesForKeysWithDictionary:data];
            [weakSelf dismissViewControllerAnimated:YES completion:nil];
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
#pragma mark - HWPanModalPresentable
#pragma mark - HWPanModalPresentable
- (BOOL)shouldRespondToPanModalGestureRecognizer:(UIPanGestureRecognizer *)panGestureRecognizer{
    CGPoint loc = [panGestureRecognizer locationInView:self.view];
    return !CGRectContainsPoint(self.view.frame, loc);

}
- (PanModalHeight)longFormHeight {
    return PanModalHeightMake(PanModalHeightTypeMax, 0);
}

- (HWBackgroundConfig *)backgroundConfig{
    HWBackgroundConfig *config = [HWBackgroundConfig new];
    config.backgroundAlpha = 0.7;
    return config;
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (CGFloat)cornerRadius{
    return 16.0;
}

- (CGFloat)topOffset{
    return KScreen_H-(312+KSafeAreaBottomHeight);
}

- (PanModalHeight)shortFormHeight {
    return [self longFormHeight];
}
- (BOOL)isAutoHandleKeyboardEnabled{
    return NO;
}

- (BOOL)showDragIndicator {
    return NO;
}
- (BOOL)allowsDragToDismiss {
    return NO;
}
-(BOOL)isPanScrollEnabled{
    return NO;
}


@end
